package ch.fusun.baron.coatofarms.ui.background;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;

import ch.fusun.baron.coatofarms.ui.COAColor;

/**
 * Diagonal Down Background
 */
public class DiagonallyDownDividedBackground implements COABackground {

	private COAColor bottom;
	private COAColor top;

	/**
	 * Empty constructor
	 */
	public DiagonallyDownDividedBackground() {
	}

	/**
	 * @param colorTop
	 *            The color on the top
	 * @param colorBottom
	 *            The color on the bottom
	 * 
	 */
	public DiagonallyDownDividedBackground(COAColor colorTop,
			COAColor colorBottom) {
		this.top = colorTop;
		this.bottom = colorBottom;
	}

	@Override
	public void drawBackground(GC gc, int x, int y, int width, int height) {
		short[] rgbT = top.getColorRGB();
		short[] rgbB = bottom.getColorRGB();
		gc.setBackground(new Color(gc.getDevice(), rgbT[0], rgbT[1], rgbT[2]));
		int[] pointArray = new int[6];

		int left = x - width / 2;
		int right = x + width / 2;
		int bottom = y - height / 2;
		int top = y + height / 2;

		pointArray[0] = left;
		pointArray[1] = bottom;
		pointArray[2] = right;
		pointArray[3] = top;
		pointArray[4] = left;
		pointArray[5] = top;
		gc.fillPolygon(pointArray);

		gc.setBackground(new Color(gc.getDevice(), rgbB[0], rgbB[1], rgbB[2]));
		pointArray[0] = left;
		pointArray[1] = bottom;
		pointArray[2] = right;
		pointArray[3] = top;
		pointArray[4] = right;
		pointArray[5] = bottom;
		gc.fillPolygon(pointArray);
	}

	@Override
	public String uniqueCode() {
		return "DiagonallyDownDividedBackground" + bottom + top;
	}
}
